package top.deepdesigner.controller.user;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.deepdesigner.annotation.RequiresPermissionsDesc;
import top.deepdesigner.pojo.DtsAddress;
import top.deepdesigner.service.DtsAddressService;
import top.deepdesigner.util.ResponseUtil;
import top.deepdesigner.vo.CommonListVO;

import java.util.HashMap;
import java.util.List;

/**
 * Start up <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/21 星期三 22:19:38 <br/>
 */
@RestController
@CrossOrigin
@RequestMapping("/admin/address")
public class AddressController {

  @Autowired
  private DtsAddressService addressService;

  //获取地址列表
  @RequiresPermissionsDesc(menu = {"用户管理", "收货地址"}, button = "获取列表")
  @RequiresPermissions(value = {"admin:address:list"})
  @GetMapping("/list")
  public Object list(@RequestParam HashMap<String, Object> params,
                     @RequestParam(defaultValue = "") String name,
                     @RequestParam(defaultValue = "") Integer userId) {
    Integer page = Integer.parseInt((String) params.get("page"));
    Integer limit = Integer.parseInt((String) params.get("limit"));
    String sort = (String) params.get("sort");
    String order = (String) params.get("order");

    CommonListVO<DtsAddress> addressListVO = new CommonListVO<>();
    //获取分页用户角色数量
    Long count = addressService.getAddressCount();
    List<DtsAddress> dtsAccountTraces = addressService.getAddressList(page, limit, sort, order, name, userId);
    addressListVO.setTotal(count);
    addressListVO.setItems(dtsAccountTraces);
    return ResponseUtil.ok(addressListVO);
  }

}